<!DOCTYPE html>
<html lang="en">

<head>
    <meta charset="UTF-8">
    <meta http-equiv="X-UA-Compatible" content="IE=edge">
    <meta name="viewport" content="width=device-width, initial-scale=1.0">
    <title>Document</title>
    <style>
        .box {
            width: 500px;
            margin: 0 auto;
        }

        header {
            width: 100%;
            height: 50px;
            text-align: center;
            line-height: 50px;
            background-color: pink;
        }

        img {
            width: 100%;
        }
    </style>
</head>

<body>
    <div id="root">

    </div>
</body>
<script src="../react.js"></script>
<script src="../react-dom.js"></script>
<!-- 用来将jsx语法转化为js语法 -->
<script src="https://cdn.staticfile.org/babel-standalone/6.26.0/babel.min.js"></script>
<script src="https://cdn.bootcdn.net/ajax/libs/jquery/3.6.3/jquery.js"></script>
<script type="text/babel">

    class App extends React.Component {
        state = {
            keyWords: ''
        }
        render() {
            let { keyWords } = this.state;
            return (
                <div className='box'>
                    <header>
                        <input type="text" placeholder='请输入想要查询的星座' value={keyWords} onChange={(e) => {
                            this.setState({
                                keyWords: e.target.value
                            })
                        }} />
                    </header>
                    <Child keyWords={keyWords} />
                </div>
            )
        }
    }
    class Child extends React.Component {
        state = {
            list: [
                {
                    name: "白羊座",
                    url: "./image/baiyang.png"
                }, {
                    name: "处女座",
                    url: "./image/chunv.png"
                }, {
                    name: "金牛座",
                    url: "./image/jinniu.png"
                }, {
                    name: "巨蟹座",
                    url: "./image/juxie.png"
                }, {
                    name: "魔羯座",
                    url: "./image/moxie.png"
                }, {
                    name: "射手座",
                    url: "./image/sheshou.png"
                }, {
                    name: "狮子座",
                    url: "./image/shizi.png"
                }, {
                    name: "双鱼座",
                    url: "./image/shuangyu.png"
                }, {
                    name: "双子座",
                    url: "./image/shuangzi.png"
                }, {
                    name: "水平座",
                    url: "./image/shuiping.png"
                }, {
                    name: "天秤座",
                    url: "./image/tiancheng.png"
                }, {
                    name: "天蝎座",
                    url: "./image/tianxie.png"
                },
            ],

        }
        render() {
            let { list } = this.state;
            console.log(this.props);
            // 父组件传递过来的输入内容
            let { keyWords } = this.props;
            return (

                <div>
                    {
                        list.map((item, index) => {
                            return (
                                item.name.includes(keyWords) && <img key={index} src={item.url} alt='' />

                            )
                        })
                    }
                </div>
            )
        }

    }
    ReactDOM.render(<App />, document.getElementById('root'))
</script>

</html>